class IUP_WIDGET

inherit
	ANY
	HASHABLE
	IUP_GET_POINTER
	IUP_INTERFACE
		export
			{NONE} All
		end

create {IUP}
   make

feature {IUP}

	make
		do
			-- Just create an IUP_WIDGET not associated with a real widget.
		end
	
feature {ANY}

	widget: POINTER

	hash_code: INTEGER_32
		do
			Result := Current.default_pointer.hash_code
		end

	-- Widget name
	set_widget_name (name: STRING)
		local
			p: POINTER
		do
			p := int_set_widget_name(get_pointer(name.to_c), widget)

			--if p /= default_pointer then
			--	io.put_string("There was a previous widget with this name. %N")
			--end
		end

	map: STRING
		-- Creates (maps) the native interface objects corresponding to the given 
		-- IUP interface elements.
		--
		-- It will also called recursively to create the native element of all 
		-- the children in the element's tree.
		--
		-- The element must be already attached to a mapped container, except the 
		-- dialog. A child can only be mapped if its parent is already mapped.
		--
		-- This function is automatically called before a dialog is shown in 
		-- show, show_xy or popup.
		--
	   -- Returns: IUP_NOERROR if successful. If the element was already mapped 
		-- returns IUP_NOERROR. If the native creation failed returns IUP_ERROR.
		local
			r: INTEGER
		do
			r := int_map(widget)

			if r.is_equal(0) then
				Result := "IUP_NOERROR"
			else
				Result := "IUP_ERROR"
			end
		end

	unmap
		-- Unmap the element from the native system. It will also unmap all its 
		-- children.
		--
		-- It will NOT detach the element from its parent, and it will NOT 
		-- destroy the IUP element.
		do
			int_unmap(widget);
		end
			
	refresh
		-- Updates the size and layout of all controls in the same dialog.
		do
			iup_open.iup_refresh(Current)
		end

	update_control
		-- Mark the element to be redraw when the control returns 
		-- to	the system.
		do
			iup_open.iup_update(Current)
		end

	redraw
		-- Force the element to be redrawn immediately.
		do
			iup_open.iup_redraw(Current, 0)
		end

	destroy
		-- Explicitly destroy de IUP widget.
		do
			iup_open.delete_widget_for_object (widget, Current)
		end

	-- Theme attributes

	set_theme (name: STRING)
		-- Applies a set of attributes to a control. The THEME attributes are 
		-- inheritable.
		do
			iup_open.set_attribute(Current, "THEME", name)
		end

	set_ntheme (name: STRING)
		-- Like "set_theme" but NOT inheritable.
		do
			iup_open.set_attribute(Current, "NTHEME", name)
		end


feature {IUP} -- Internal handle of callbacks

	-- The following should be redefined when appropriate.

	-- Common callbacks
	
	execute_map: STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_unmap: STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_destroy: STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_getfocus: STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_killfocus: STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_enterwindow: STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_leavewindow: STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_k_any (c: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_help
		do
			-- Nothing to be done.
		end

	execute_action: STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Dialogs
	execute_close: STRING
		do
			Result := "IUP_DEFAULT"
		end
	
	execute_copydata (cmdline: STRING; size: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Also canvas, label, list, text
	execute_dropfiles (filename: STRING; num: INTEGER; x: INTEGER; y: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_mdiactivate: STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_move (x: INTEGER; y: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Also for canvas.
	execute_resize (width: INTEGER; height: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_show (state: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_trayclick (but: INTEGER; pressed: INTEGER; dclick: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- File dialog
	execute_file (file_name, status: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end
	
	-- Color dialog
	execute_colorupdate: STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Progress bar dialog
	execute_cancel: STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Buttons, canvas, label, list, text
	execute_button (btn, pressed, x, y: INTEGER; status: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Calendar, also split, text, flat button
	execute_valuechanged: STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Canvas
	execute_action_fnff (posx, posy: REAL_32): STRING
		do
			Result := "IUP_DEFAULT"
		end
	
	execute_focus (focus: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Also list, text
	execute_motion (x, y: INTEGER; status: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_keypress (c, press: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_scroll (op: INTEGER; posx, posy: REAL_32): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_wheel (delta: REAL_32; x, y: INTEGER; status: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Detach box
	execute_detached (new_parent: IUP_DIALOG; x, y: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_restored (old_parent: IUP_WIDGET; x, y: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Expander
	execute_openclose (state: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_extrabutton (button, pressed: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Link
	execute_click (url: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- List
	execute_action_fnsii (text: STRING; item, state: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Also text
	execute_caret (lin, col, pos: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_dblclick (item: INTEGER; text: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_dragdrop (drag_id, drop_id, isshift, iscontrol: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_dropdown (state: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_edit (c: INTEGER; new_value: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_multiselect (value: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Spin, Spin box
	execute_spin (inc: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Tabs
	execute_tabchange (new_tab, old_tab: IUP_WIDGET): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_tabchangepos (new_pos, old_pos: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_tabclose (pos: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_rightclick (pos: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Text
	execute_action_fnis (c: INTEGER; new_value: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_maskfail (new_value: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Toggle
	execute_action_fni (state: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Tree
	execute_selection (id, status: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_multiselection (ids: POINTER; n: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_multiunselection (ids: POINTER; n: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_branchopen (id: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_branchclose (id: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_executeleaf (id: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_showrename (id: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_rename (id: INTEGER; title: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_noderemoved (userdata: POINTER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_togglevalue (id, state: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Menu item and submenu
	execute_highlight: STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Menu
	execute_open: STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_menuclose: STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Drag callbacks
	execute_dragbegin (x, y: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_dragdatasize (type: STRING): INTEGER
		do
			Result := 0
		end

	execute_dragdata (type: STRING; data: POINTER; size: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_dragend (action: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Drop callbacks
	execute_dropdata (type: STRING; data: POINTER; size, x, y: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_dropmotion (x, y: INTEGER; status: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Recent file menu callback
	execute_recent: STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Get param
	execute_param (handle: POINTER; param_index: INTEGER; user_data: POINTER): INTEGER
		do
			Result := 0
		end

	-- Flat button
	execute_flat_action: STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_flat_button (btn, pressed, x, y: INTEGER; status: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_flat_focus (focus: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_flat_enterwindow: STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_flat_leavewindow: STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Cells

	execute_draw (line, column, xmin, xmax, ymin, ymax: INTEGER; canvas: POINTER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_height (line: INTEGER): INTEGER
		do
			Result := 30
		end

	execute_hspan (line, column: INTEGER): INTEGER
		do
			Result := 1
		end

	execute_mouseclick (btn, prd, l, c, x, y: INTEGER; s: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_mousemotion (l, c, x, y: INTEGER; r: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_ncols: INTEGER
		do
			Result := 10
		end

	execute_nlines: INTEGER
		do
			Result := 10
		end

	execute_scrolling (l, c: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_vspan (l, c: INTEGER): INTEGER
		do
			Result := 1
		end

	execute_width (c: INTEGER): INTEGER
		do
			Result := 60
		end

	-- Color bar

	execute_cell (cell: INTEGER): TUPLE[INTEGER, INTEGER, INTEGER]
		do
			Result := [(0).to_integer_32, (0).to_integer_32, (0).to_integer_32]
		end

	execute_extended (cell: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_select (cell, type: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_switch (prim_cell, sec_cell: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Matrix

	execute_action_fniiiis (key, lin, col, edition: INTEGER; value: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_click_fniis (lin, col: INTEGER; status: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_colresize (col: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_release (lin, col: INTEGER; status: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_resizematrix (width, height: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_mousemove (lin, col: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_enteritem (lin, col: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_leaveitem (lin, col: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_scrolltop (lin, col: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_bgcolor (lin, col: INTEGER; red, green, blue: POINTER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_fgcolor (lin, col: INTEGER; red, green, blue: POINTER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_font (lin, col: INTEGER): STRING
		do
			Result := ""
		end

	execute_type (lin, col: INTEGER): STRING
		do
			Result := ""
		end

	execute_dropcheck (lin, col: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_translatevalue (lin, col: INTEGER; value: STRING): STRING
		do
			Result := ""
		end

	execute_togglevalue_fniii (lin, col, status: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_drop (drop: IUP_DROP; lin, col: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_menudrop (drop: IUP_DROP; lin, col: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_dropselect (lin, col: INTEGER; drop: IUP_DROP; t: STRING; i, v: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_edition (lin, col, mode, update: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_value (lin, col: INTEGER): STRING
		do
			Result := ""
		end

	execute_value_edit (lin, col: INTEGER; newval: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_mark (lin, col: INTEGER): INTEGER
		do
			Result := (0).to_integer_32
		end

	execute_markedit (lin, col, marked: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Flat tabs

	execute_flat_motion (x, y: INTEGER; status: STRING): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Drop button

	execute_dropshow (state: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Dial

	execute_button_press (angle: REAL_64): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_button_release (angle: REAL_64): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_mousemove_fnd (angle: REAL_64): STRING
		do
			Result := "IUP_DEFAULT"
		end

	-- Color browser

	execute_change (red, green, blue: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	execute_drag (red, green, blue: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

feature {NONE}

	-- Internal

	set_widget (wgt: detachable POINTER)
		do
			if attached wgt as a_wgt then
				widget := a_wgt
				iup_open.set_widget_for_object (widget, Current)
			end
		end

	int_set_widget_name(name, wgt: POINTER): POINTER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return IupSetHandle ($name, $wgt);"
      end

	int_map(wgt: POINTER): INTEGER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return IupMap ($wgt);"
      end

	int_unmap(wgt: POINTER)
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"IupUnmap ($wgt);"
      end

end

-- The MIT License (MIT)

-- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
